package pres.lnk.learn.designpattern.n_chainofresponsibility;

/**
 * 责任链抽象对象，负责整个链的控制，链上的具体职责人继承于此，然后只专注处理业务即可
 * @Author lnk
 * @Date 2018/4/12
 */
public abstract class AbstractLogger {
    public static final int DEBUG = 1;
    public static final int INFO = 2;
    public static final int ERROR = 3;

    private int level;
    private AbstractLogger nextLogger;

    public AbstractLogger(int level) {
        this.level = level;
    }

    public void message(int level, String message){
        if(this.level <= level){
            write(message);
        }
        if(nextLogger != null){
            nextLogger.message(level, message);
        }
    }

    abstract void write(String message);

    public void setNextLogger(AbstractLogger nextLogger) {
        this.nextLogger = nextLogger;
    }
}
